def lolkek(u):
    t = True
    for b in range(2, int(u ** 0.5)+1):
        if u % b == 0:
            t = False
            break
    return t


k = int(input())
if k < 1000 or k > 9999:
    print(0)
else:
    chicken_nugget = str(k)
    maxi = 0
    for d in range(len(chicken_nugget)):
        for qw in range(d+1, len(chicken_nugget)+1):
            lolly = int(chicken_nugget[d:qw])
            if lolkek(lolly):
                maxi = max(maxi, lolly)
    print(maxi)
